/// [Prime Number](https://projecteuler.net/problem=7)
fn main() {
    for &num in &[6, 10001] {
        println!("The {}st prime number is {}", num, find_prime(num));
    }
}
/// 记录质因数列表，平方缩小范围
fn find_prime(length: usize) -> usize {
    let mut primes = vec![2];
    let mut num = 3;
    while primes.len() < length {
        for item in primes.iter() {
            if num % item == 0 {
                break;
            }
            if item * item > num {
                primes.push(num);
                break;
            }
        }
        num += 1;
    }
    primes[primes.len() - 1]
}

#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn is_work() {
        assert_eq!(find_prime(6), 13);
    }
}
